/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.animation
{
	import flash.display.FrameLabel;
	import flash.events.EventDispatcher;

	public class MovieClipConteiner extends EventDispatcher
	{
		protected var movieClips:Vector.<AnimatedMovieClip>;
		
		public function MovieClipConteiner()
		{
			movieClips = new Vector.<AnimatedMovieClip>();
		}
		
		public function removeMovieClips():void{			
			movieClips = new Vector.<AnimatedMovieClip>();
			stop(true);
		}
		
		public function addMovieClip(value:AnimatedMovieClip):AnimatedMovieClip{
			if(value.testMovieClipLabels()){
				movieClips.push(value);
			}
			return value;
		}
		
		public function removeMovieClip(Id:String):AnimatedMovieClip{
			if(Id){
				for (var i:int = 0; i < movieClips.length; i++){
					var movieClip:AnimatedMovieClip = movieClips[i];
					if(movieClip.Id == Id){
						movieClips.splice(i, 1);
						return movieClip;
					}
				}
			}
			
			return null;
		}
		
		public function play(event:AnimatedEvent = null):void{
			for each( var movieClip:AnimatedMovieClip in movieClips){
				movieClip.play();
			}
		}
		
		public function stop(force:Boolean):void{
			for each( var movieClip:AnimatedMovieClip in movieClips){
				movieClip.stop();
			}
		}
		
		public function gotoAndStop(frame:FrameLabel):void{
			for each( var movieClip:AnimatedMovieClip in movieClips){
				movieClip.gotoAndStop(frame);
			}			
		}
		
		public function nextFrame():void{
			for each( var movieClip:AnimatedMovieClip in movieClips){
				movieClip.nextFrame();
			}			
		}
		
		public function prevFrame():void{
			for each( var movieClip:AnimatedMovieClip in movieClips){
				movieClip.prevFrame();
			}
		}
	}
}